本文以UML类图方式给出The ONE中DTNHost
、MessageRouter
、Message
间的关系,并以示意图的形式给出incomingMessage
, messages
, deliverredMessages
间的联系,即消息在The ONE的流动。
1. UML类图
每个DTNHost
有一个MessageRouter
(一一对应),MessageRouter
有3个关于消息的HashMap
。同时,消息的属性包含源DTNHost
、目标DTNHost
以及消息所经过DTNHost
组成的列表(即path
),其UML类图如下:
2. Message与MessageRouter
首先,DTNHost
与MessageRouter
是一一对应的,而MessageRouter
分别维护着多个消息HashMap
(基于哈希表的Map
接口的实现),相关源代码如下:
//MessageRouter.java
private HashMap<String, Message> messages; //The messages this router is carrying
private HashMap<String, Message> incomingMessages; //The messages being transferred with msgID_hostName keys
private HashMap<String, Message> deliveredMessages; //The messages this router has received as the final recipient
private HashMap<String, Object> blacklistedMessages; //The messages that Applications on this router have blacklisted
Message包含如下成员变量:
//Message.java
/*** 标识消息 ***/
private String id; //Identifier of the message
private int uniqueId; //Unique ID of this message
private int size; //Size of the message (bytes)
private static int nextUniqueId; //Next unique identifier to be given
/*** 记录消息传输路径 ***/
private DTNHost from;
private DTNHost to;
private List<DTNHost> path; //List of nodes this message has passed
/*** Time to live ***/
private double timeReceived; //The time this message was received
private double timeCreated; //The time when this message was created
private int initTtl; //Initial TTL of the message
public static final String TTL_SECONDS_S = "Scenario.ttlSeconds";
private static boolean ttlAsSeconds = false; //ture for seconds, false for minutes
public static final int INFINITE_TTL = -1; //Value for infinite TTL of message
/*** response message ***/
private int responseSize; //0 if no response is requested
private Message requestMsg; //if this message is a response message, this is set to the request msg
/** Container for generic message properties. Note that all values
* stored in the properties should be immutable because only a shallow
* copy of the properties is made when replicating messages */
private Map<String, Object> properties;
private String appID; //Application ID of the application that created the message
3. 消息缓冲区
The ONE消息的转换如下图所示(visio源文件:The ONE消息转换示意图.vsdx)。新创建的消息放在messages
,正在传输的消息放在incomingMessages
;传输成功的消息若为目的节点则放在deliverredMessages
,否则放在messages
。